
import os
import json

# 指定要读取的文件夹路径
folder_path = '/Users/daxiang/Downloads/歌词'

# 创建一个空字典来存储文件名和内容
files_content = {}

# 遍历指定文件夹
for filename in os.listdir(folder_path):
    # 检查文件是否是普通文件
    if os.path.isfile(os.path.join(folder_path, filename)):
        # 获取不带后缀的文件名
        file_key = os.path.splitext(filename)[0]

        try:
            file_key.index(".")
        except:
            print(f"--------file_key: ", file_key)
            # 打开并读取文件内容
            with open(os.path.join(folder_path, filename), 'r', encoding='utf-8') as file:
                files_content[file_key] = file.read()
            pass

# 将字典保存为JSON文件
with open('output.json', 'w', encoding='utf-8') as json_file:
    json.dump(files_content, json_file, ensure_ascii=False, indent=4)

print("JSON文件已生成。")
